package edu.ubb.scrumster.model.repository;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import edu.ubb.scrumster.model.model.AbstractModel;
import edu.ubb.scrumster.model.model.Notification;
import edu.ubb.scrumster.model.model.User;

public class NotificationRepository {

	public NotificationRepository() {
	}

	public ArrayList<Notification> getAllNotification() {
		ArrayList<Notification> list = new ArrayList<Notification>();
		for (AbstractModel d : DatabaseAccess.getInstance().getAll(DatabaseAccess.NOTIFICATION)){
			list.add(getNotificationById(((Notification) d).getId()));
		}
		return list;
	}

	public void addNotification(Notification g) {
		DatabaseAccess.getInstance().addData(g);
	}

	public void updateNotification(Notification data) {
		DatabaseAccess.getInstance().updateData(data);
	}

	public void deleteNotification(Notification data) {
		DatabaseAccess.getInstance().deleteData(data);
	}

	public Notification getNotificationById(int id) {
		Notification n=(Notification)DatabaseAccess.getInstance().getDataById(id, DatabaseAccess.NOTIFICATION);
		n.setSender((User)DatabaseAccess.getInstance().getDataById(n.getSender().getId(), DatabaseAccess.USER));
		n.setReceiver((User)DatabaseAccess.getInstance().getDataById(n.getReceiver().getId(), DatabaseAccess.USER));
		return n;
	}
}
